package com.example.jedis_pool.demo;

import com.example.jedis_pool.jedis_config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.Jedis;

import java.util.*;
import java.util.Random;

public class GradeSort {

    public static void main(String[] args) {

        jedis.select(1);
        GradeSort.print(100);
        jedis.close();
    }

    //获取连接
    private static Jedis jedis= Config.JedisPool().getResource();

    public static void randomGrade(int stu_num){

        Random random = new Random();

        //控制自动生成的学生数
        for (int s=1;s<=stu_num;s++){
            String name="小明"+s;
            String gread="";

            //随机生成学生的分数
            for (int i =0;i<2;i++){
                //随机生成0-10之间的任意一个数，不包括10
                int gd=random.nextInt(10);
                gread+=gd;
            }

            jedis.zadd("student",Double.parseDouble(gread),name);

        }
    }
    public static void print(int stu_num){

        GradeSort.randomGrade(stu_num);
        Set s=jedis.zrangeWithScores("student",0,-1);

            for (Object c : s) {
                    System.out.println(c);
            }

    }


}
